package com.jmemoir.mq.rabbitmq.controller;

import com.jmemoir.base.common.dto.Result;
import com.jmemoir.mq.rabbitmq.utils.RabbitMqUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试控制层
 *
 * @author Tellsea
 * @date 2023/9/5
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/rabbitMqTest")
public class RabbitMqTestController {

    private final RabbitMqUtils rabbitMqUtils;

    @GetMapping("/simple")
    public Result<String> simple() {
        rabbitMqUtils.sendMessage("spring.simple.queue", "简单模型-simple：生产者直接发送到队列");
        return Result.success("发送成功");
    }

    @GetMapping("/work")
    public Result<String> work() {
        rabbitMqUtils.sendMessage("spring.work.queue", "简单模型-work：生产者直接发送到队列，有多个消费者");
        return Result.success("发送成功");
    }

    @GetMapping("/fanout")
    public Result<String> fanout() {
        rabbitMqUtils.sendMessage("spring.fanout.exchange", "", "订阅模型-Fanout：生产者 > 交换机 > 发送给所有绑定交换机的队列");
        return Result.success("发送成功");
    }

    @GetMapping("/direct")
    public Result<String> direct() {
        rabbitMqUtils.sendMessage("spring.direct.exchange", "direct", "订阅模型-Direct：生产者 > 交换机 > 发送给所有绑定交换机、且路由Key相等的队列");
        return Result.success("发送成功");
    }

    @GetMapping("/topic")
    public Result<String> topic() {
        rabbitMqUtils.sendMessage("spring.topic.exchange", "user.insert", "新增用户");
        rabbitMqUtils.sendMessage("spring.topic.exchange", "user.delete", "删除用户");
        rabbitMqUtils.sendMessage("spring.topic.exchange", "student.insert", "新增学生");
        rabbitMqUtils.sendMessage("spring.topic.exchange", "student.delete", "删除学生");
        return Result.success("发送成功");
    }

    @GetMapping("/delay")
    public Result<String> delay() {
        rabbitMqUtils.sendDelayMessage("spring.delay.exchange", "spring.delay.routing.key", "延迟队列消息", 10000);
        return Result.success("发送成功");
    }
}
